/**
 * 
 */
package com.virxue.baseweb.bo;

import java.util.ArrayList;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.virxue.baseweb.dao.ChatRecordDao;
import com.virxue.baseweb.po.ChatRecordPo;
import com.virxue.baseweb.vo.ChatRecordVo;

/**
 * @ClassName ChatRecordBo
 * @Description 聊天记录类
 *
 * @author sunhaojie 3113751575@qq.com
 * @date 2015年11月7日 下午4:05:31
 */
@Service
public class ChatRecordBo {

    @Autowired
    private ChatRecordDao chatRecordDao;

    public boolean addChat(String username, String content) {
        ChatRecordPo chatRecordPo = new ChatRecordPo();
        chatRecordPo.setUserName(username);
        chatRecordPo.setContent(content);
        int insertRowNum = chatRecordDao.insert(chatRecordPo);
        if (insertRowNum != 1) {
            return false;
        }
        return true;
    }

    /**
     * 查询最近的num聊天记录
     * 
     * @Title listRecently
     * @param @param num
     * @param @return
     * @return List<ChatRecordPo>
     *
     * @author sunhaojie 3113751575@qq.com
     * @date 2015年11月7日 下午4:09:43
     */
    public List<ChatRecordVo> listRecently(int num) {
        List<ChatRecordPo> list = chatRecordDao.list(num);
        List<ChatRecordVo> resultList = new ArrayList<ChatRecordVo>();
        for (ChatRecordPo chatRecordPo : list) {
            ChatRecordVo chatRecordVo = new ChatRecordVo(chatRecordPo);
            resultList.add(chatRecordVo);
        }
        return resultList;
    }
}
